﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace MiserDB.DataHelp
{
    public class ActionTranHelper : QueryHelper
    {
        ITransaction tran = null;

        public ActionTranHelper()
            : base()
        {
            tran = Session.BeginTransaction();
        }

        public virtual object Save<T>(T obj) where T : class
        {
            return Session.Save(obj);
        }

        public override void Dispose()
        {
            tran.Commit();

            base.Dispose();
        }

        public virtual void SaveOrUpdate<T>(T obj) where T : class
        {
            Session.Clear();
            Session.SaveOrUpdate(obj);
        }

        public virtual void Update<T>(T obj) where T : class
        {
            Session.Update(obj);
        }

    }
}
